package org.come.control;

import java.math.BigDecimal;

import org.come.Frame.NPCJfram;
import org.come.action.NpcMenuAction;
import org.come.entity.RoleSummoning;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.SendRoleAndRolesummingUntil;
import org.come.until.UserMessUntil;

public class SelectOptionControl implements NpcMenuAction {

	@Override
	public void menuControl(String type) {
		if ("HP".equals(type)) {
			selectValue("HP");
		} else if ("MP".equals(type)) {
			selectValue("MP");
		} else if ("AP".equals(type)) {
			selectValue("AP");
		} else if ("SP".equals(type)) {
			selectValue("SP");
		} else if ("是".equals(type)) {
			selectChange("是");
		} else if ("否".equals(type)) {
			selectChange("否");
		}
	}

	// 选择属性的方法
	public void selectValue(String flag) {
		String[] mes = NPCJfram.getNpcJfram().getNpcjpanel().getPettype().split("\\|");
		int value = 0;
		if ("HP".equals(flag)) {
			value = 0;
		} else if ("MP".equals(flag)) {
			value = 1;
		} else if ("AP".equals(flag)) {
			value = 2;
		} else if ("SP".equals(flag)) {
			value = 3;
		}
		String sendmes = Agreement.getAgreement().userpetAgreement("N|" + mes[0] + "|" + value);
		SendMessageUntil.toServer(sendmes);
	}

	// 选择是否变化造型的方法
	public void selectChange(String flag) {
		if (!"是".equals(flag)) {
			return;
		}
		String[] mes = NPCJfram.getNpcJfram().getNpcjpanel().getPettype().split("\\|");
		BigDecimal sid = new BigDecimal(mes[0]);
		RoleSummoning pet = null;
		if (sid != null) {
			for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
				if (UserMessUntil.getPetListTable().get(i).getSid().longValue() == sid.longValue()) {
					pet = UserMessUntil.getPetListTable().get(i);
					break;
				}
			}
		}
		if (pet == null) {
			return;
		}
		changePifu(pet);
		SendRoleAndRolesummingUntil.sendRoleSumming(pet);
	}

	// 变换造型
	public void changePifu(RoleSummoning pet) {
		if ("200102".equals(pet.getSummoningid())) {
			pet.setSummoningskin("400105");
		} else if ("200103".equals(pet.getSummoningid())) {
			pet.setSummoningskin("400102");
		} else if ("200104".equals(pet.getSummoningid())) {
			pet.setSummoningskin("400106");
		} else if ("200105".equals(pet.getSummoningid())) {
			pet.setSummoningskin("400105");
		} else if ("200106".equals(pet.getSummoningid())) {
			pet.setSummoningskin("400103");
		} else if ("200107".equals(pet.getSummoningid())) {
			pet.setSummoningskin("400104");
		}
	}
}
